package com.ruoyi.web.controller.life;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.life.LifeZhouYi;
import com.ruoyi.system.service.life.ILifeZhouYiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 周易Controller
 *
 * @author ruoyi
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/life/yi")
public class LifeZhouYiController extends BaseController {
    @Autowired
    private ILifeZhouYiService lifeZhouYiService;

    /**
     * 查询周易列表
     */
    @PreAuthorize("@ss.hasPermi('life:yi:list')")
    @GetMapping("/list")
    public TableDataInfo list(LifeZhouYi lifeZhouYi) {
        startPage();
        List<LifeZhouYi> list = lifeZhouYiService.selectLifeZhouYiList(lifeZhouYi);
        return getDataTable(list);
    }

    /**
     * 导出周易列表
     */
    @PreAuthorize("@ss.hasPermi('life:yi:export')")
    @Log(title = "周易", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifeZhouYi lifeZhouYi) {
        List<LifeZhouYi> list = lifeZhouYiService.selectLifeZhouYiList(lifeZhouYi);
        ExcelUtil<LifeZhouYi> util = new ExcelUtil<LifeZhouYi>(LifeZhouYi.class);
        util.exportExcel(response, list, "周易数据");
    }

    /**
     * 获取周易详细信息
     */
    @PreAuthorize("@ss.hasPermi('life:yi:query')")
    @GetMapping(value = "/{lGuaId}")
    public AjaxResult getInfo(@PathVariable("lGuaId") Long lGuaId) {
        return success(lifeZhouYiService.selectLifeZhouYiByLGuaId(lGuaId));
    }

    /**
     * 新增周易
     */
    @PreAuthorize("@ss.hasPermi('life:yi:add')")
    @Log(title = "周易", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifeZhouYi lifeZhouYi) {
        return toAjax(lifeZhouYiService.insertLifeZhouYi(lifeZhouYi));
    }

    /**
     * 修改周易
     */
    @PreAuthorize("@ss.hasPermi('life:yi:edit')")
    @Log(title = "周易", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifeZhouYi lifeZhouYi) {
        return toAjax(lifeZhouYiService.updateLifeZhouYi(lifeZhouYi));
    }

    /**
     * 删除周易
     */
    @PreAuthorize("@ss.hasPermi('life:yi:remove')")
    @Log(title = "周易", businessType = BusinessType.DELETE)
    @DeleteMapping("/{lGuaIds}")
    public AjaxResult remove(@PathVariable Long[] lGuaIds) {
        return toAjax(lifeZhouYiService.deleteLifeZhouYiByLGuaIds(lGuaIds));
    }
}
